import pygame
import random
import math

from CTextureManager import CTextureManager
from CSoundManager import CSoundManager

class CPickup(object):
    """ Holds information about pickup items on the map. """
    
    LEFT = 0
    RIGHT = 1
    UP = 2
    DOWN = 3
    
    def __init__(self , name , startingPoint , map , id , value ):
        """ Create the player object, binding the sprite sheet image and setting the starting x , y coordinates and a pointer to the map it will be residing in. ID is a unique identifier. """
        
        # Load our spritesheet. SpriteSheets are based directly on the name of the enemy.
        # If our texture isn't loaded, load it, else just get the instance
        if( CTextureManager.IsLoadedTexture(name) == False ):
            self.mSpriteSheet = CTextureManager.LoadTexture("img/P_" + name + ".gif" , name )
        else:
            self.mSpriteSheet = CTextureManager.GetTexture( name )
            
        # Load our audio files. Also based on enemy name.
        # Load attack audio
        if( CSoundManager.IsLoadedSound(name + "_sound") == False ):
            self.mPickupSound = CSoundManager.LoadSound("audio/P_" + name + ".ogg" , name + "_sound" )
        else:
            self.mPickupSound = CSoundManager.GetSound( name + "_sound" )
        
        self.mSpriteRect = pygame.Rect( ( 0 , 0 ) , ( 16 , 16 ) )
        self.mXPos = startingPoint[0] * 16
        self.mYPos = startingPoint[1] * 16
        self.mName = name
        self.mCurrentMap = map
        self.mID = id
        self.mValue = value
        self.mIsPickedUp = False
        
        # Load gold characteristics
        #if( name == "Gold"):

        
    def draw(self , inScreen):
        """ Draw our pickup sprite. """
        if( self.mIsPickedUp == False):
            inScreen.blit( self.mSpriteSheet , ( self.mXPos , self.mYPos ) , self.mSpriteRect )

    def GetWorldPos(self):
        """ Get the world position tuple of the pickup. Useful for handling collisions within the tile set etc. """
        return ( self.mYPos/16 , self.mXPos/16 )                 

    def Pickup(self):
        """ Play sound and set item as picked up. """
        
        self.mPickupSound.play()
        self.mIsPickedUp = True

    def GetName(self):
        """ Get the name of this item. """
        return self.mName
    
    def GetValue(self):
        """ Get the value of this item. """
        return self.mValue
                
    def Step(self):
        """ Handle being picked up and clean up after self. """
        
        # If our enemy is dead after a step, decompose/remove it
        if( self.mIsPickedUp == True ):
                self.mCurrentMap.GetPickups().remove( self )
        
    
        
        
        
         

